package io.xccit.security.util;

import io.xccit.common.utils.MD5;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Component;

/**
 * @author CH_ywx
 * @date 2023-06-27
 * @description 自定义密码加密器
 */

@Component
public class AuthMD5PassEncoder implements PasswordEncoder {

    /**
     * 密码加密
     * @param rawPassword 明文密码
     * @return 加密后的密码
     */
    @Override
    public String encode(CharSequence rawPassword) {
        return MD5.encrypt(rawPassword.toString());
    }

    /**
     *
     * @param rawPassword the raw password to encode and match
     * @param encodedPassword the encoded password from storage to compare with
     * @return 密码比对结果
     */
    @Override
    public boolean matches(CharSequence rawPassword, String encodedPassword) {
        return encodedPassword.equals(MD5.encrypt(rawPassword.toString()));
    }
}
